package com.pro.system.Repository;

import com.pro.system.entity.Movie;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Optional;

@Repository
public interface MovieRepository extends JpaRepository<Movie,Integer> {
    @Override
    List<Movie> findAll();

    @Query(value = "select * from movie where movie_id=?1 " ,nativeQuery = true)
    Movie findByid(Integer id);

    @Modifying
    @Transactional
    @Query(value = "select * from movie where name like %?1% " ,nativeQuery = true)
    public List<Movie> findByNameLike(String name);

    @Modifying
    @Transactional
    @Query(value = "select * from movie m order by m.hot desc limit :count" ,nativeQuery = true)
    public List<Movie> findOrderByHot(Integer count);
}
